package com.priv.controller;

import com.priv.exception.BusinessException;
import com.priv.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : 十一
 * @data : 18:39 2022/12/28
 * When in doubt, use brute force.
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException exception){
        /**
         * 记录日志
         * 发送消息给运维
         * 发送邮件给开发人员，exception对象发送给开发人员
         */
        return new Result(exception.getCode(), null, exception.getMessage());
    }


    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException exception){
        return new Result(exception.getCode(), null, exception.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public Result doException(Exception exception){
        /**
         * 记录日志
         * 发送消息给运维
         * 发送邮件给开发人员，exception对象发送给开发人员
         */
        return new Result(Code.SYSTEM_UNKNOW_ERR, null, "系统繁忙，请稍后再试！");
    }
}
